<template>
  <a-modal 
    :visible="visible"
    okText="提交" 
    cancelText="取消"
    :title="title"
    :maskClosable="false"
    :destroyOnClose="true"
    :keyboard="false"
    width="1000px"
    @cancel="closeModal()" 
    @ok="handleSubmit">
    <search-table :url="url" :defaultParams="defaultParams" :defaultSelectedRowKeys="checkedIds" :columns="columns" ref="searchtable"></search-table>
  </a-modal>
</template>
<script>
import { findDictNameByValue } from '@/utils/dict'
export default {
  components:{
    
  },
  props: {
    visible:{
      type:Boolean,
      default:false,
    },
    type: {
      type: [Number, String],
      default: 3
    },
    checkedIds: {
      type:Array,
      default:[]
    }
  },
  computed: {
    title () {
      return '自提地址'
    },
  },
  data () {
    return {
        url:'/address/config/page',
        defaultParams:{
          addressType:this.type,//1退货地址；2发货地址；3自提地址
        },
        columns:[
            {
                title:'编号',
                dataIndex:'id',
                key:'id',
            },
            {
                title:'地址名称',
                dataIndex:'addressName',
                key:'addressName',
            },
            {
                title:'地址类型',
                dataIndex:'addressType',
                key:'addressType',
                customRender: (text, record) => findDictNameByValue('ADDRESS_TYPE', text)
            },
            {
                title:'联系人姓名',
                dataIndex:'contactName',
                key:'contactName',
            },
            {
                title:'地址',
                dataIndex:'fullAddress',
                key:'fullAddress',
            },
            {
                title:'联系电话',
                dataIndex:'phone',
                key:'phone',
            },
        ]
    }
  },
  watch: {
    visible(value) {
      if(value){
        
      }
    }
  },
  created(){
    
  },
  mounted () {
    
  },
  methods: {
    closeModal (freshTable) {
      this.$emit('cancel', freshTable)
    },
    handleSubmit(){
      let selectKeys=this.$refs.searchtable.selectedRowKeys;
      if(selectKeys.length==0){
        if(this.type == 3) {
          this.$message.error('请选择自提地址');
        }
        if(this.type == 4) {
          this.$message.error('请选择定点配送地址');
        }
        return;
      }
      console.log('selectKeys',selectKeys)
      this.$emit('submit',selectKeys);
    }
  }
}
</script>